//
//  Audio.m
//  DolphinMusic
//
//  Created by dllo on 15/3/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "Audio.h"

@implementation Audio

-(void)dealloc
{
    [_time release];
    [_audioId release];
    [_playUrl32 release];
    [_downloadUrl release];
    [_title release];
    [_coverLarge release];
    [_nickname release];
    [_downSize release];
    [_playCount release];
    [super dealloc];
}

- (instancetype)initWithDictionary:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"trackId"]) {
        self.audioId = [value stringValue];
    }
    if ([key isEqualToString:@"downloadSize"]) {
        self.downSize = [value stringValue];
    }
    if ([key isEqualToString:@"duration"]) {
        NSInteger time = [value integerValue];
        NSString *minites = [NSString stringWithFormat:@"%ld", time / 60];
        NSString *seconds = [NSString stringWithFormat:@"%ld", time % 60];
        self.time = [NSString stringWithFormat:@"%@:%@", minites, seconds];
        if (time % 60 < 10) {
           self.time = [NSString stringWithFormat:@"%@:0%@", minites, seconds];
        }
        
    }
    if ([key isEqualToString:@"playtimes"]) {
        self.playCount = [NSString stringWithFormat:@"%.1f万", [value floatValue] / 10000];
        if ([value integerValue] < 10000) {
            self.playCount = [NSString stringWithFormat:@"%ld", [value integerValue]];
        }
    }
}

-(id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}


@end
